package com.webserver.core;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * WebServer主类
 * WebServer是一个web容器，模拟Tomcat基础功能
 * Web容器主要有两个任务
 * 1：管理部署在容器中的所有网络应用
 */
public class WebServerApplication {
    private ServerSocket serverSocket;
    public WebServerApplication(){
        try {
            System.out.println("正在启动服务端。。。");
            serverSocket = new ServerSocket(8088);
            System.out.println("服务器已启动！！！");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public void start(){
        try {
            Socket socket = serverSocket.accept();
            System.out.println("一个客户端连接上了");
            ClientHandler handler = new ClientHandler(socket);
            Thread thread = new Thread(handler);
            thread.start();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        WebServerApplication server = new WebServerApplication();
        server.start();
    }
}
